<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Breadcrumbs;
use app\modules\clinical\models\Patient;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '门诊表格';
$this->params['breadcrumbs'][] = ['label' => '临床信息', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$this->registerJsFile('@web/js/excel.js?v=1', ['depends' => 'app\assets\AppAsset']);
GLOBAL $rel;
$rel = $pt_rel_list;
?>
<?= Breadcrumbs::widget([
    'homeLink' => ['label' => '医疗管理系统', 'url' => '#'],
    'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

<div class="excel-index">

    <p>
        <?= Html::a('创建诊断表格', '##', ['class' => 'btn btn-success', 'id' => 'chooseButton']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [
                'attribute' => '姓名',
                'value' => function($data) {
                    if ($data->rel_id == 0) {
                        return Yii::$app->session->get('pt_name');
                    }

                    $relative = Patient::findOne(['pk_id'=>$data->pt_id]);
                    return $relative->pt_name;
                },
            ],
            [
                'attribute' => '与患者关系',
                'value' => function($data) {
                    GLOBAL $rel;
                    if ($data->rel_id == 0) return '';
                    return Patient::getParams('relation')[$rel[$data->pt_id]];
                },
            ],
            [
                'attribute' => 'pt_diagnose',
                'value' => function($data) {
                    switch ($data->pt_diagnose) {
                        case 'pdf': $string = 'PD复诊'; break;
                        case 'pd' : $string = 'PD初诊'; break;
                        case 'udprs' : $string = '美多芭冲击试验'; break;
                        case 'udprs2' : $string = 'UDPRS'; break;
                        case 'pdx' : $string = '帕金森病患者营养状况横断面研究病例报告表'; break;

                        default: $string = strtoupper($data->pt_diagnose); break;
                    }
                    return $string;
                },
            ],
            'crt_name',
            'crt_time',
            'update_name',
            'update_at',

            [
                'class' => 'yii\grid\ActionColumn',
                'buttons' =>[
                    'view' => function($url, $model, $key) {
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', '/clinical/excel/view?id='.$key.'&type='.$model->pt_diagnose);
                    },
                    'update' => function($url, $model, $key) {
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', '/clinical/excel/update?id='.$key.'&type='.$model->pt_diagnose);
                    },
                ],
                'template' => '{view} {update}',
            ],
        ],
    ]); ?>

</div>
